$(function(){
    //_CF.jsoncityUrl='http://345656.com/ajax/';
    try{
        var fun=eval(_CF.mod + "_" + _CF.act);
        if(typeof fun =='function'){
            fun();
        }
    }catch(e){
        //console.log( e.message );
    }

    try{
        var fun=eval(_CF.mod +"_" + _CF.act + "_" + _CF.type);
        if(typeof fun =='function'){
            fun();
        }
    }catch(e){
        //console.log( e.message );
    }

    if (_CF.uploadImgParams) {
        wx.config(_CF.uploadImgParams);
        wx.ready(function(){
            function jsuploadpic(){
                document.querySelector('#uploadpic').onclick = function () {
                    // 5 图片接口
                    // 5.1 拍照、本地选图
                    var images = {
                        localId: [],
                        serverId: []
                    };

                    wx.chooseImage({
                        success: function (res) {
                            images.localId = res.localIds;
                            //alert('已选择 ' + res.localIds.length + ' 张图片');
                            //alert(JSON.stringify(res));

                            var  lastindex = 0;
                            if(res.localIds.length>0){
                                lastindex = res.localIds.length-1;
                            }
                            var img = '<img src="'+res.localIds[lastindex]+'" style="width:50px;height:50px;"/>';
                            $('#picshow').show().html(img);

                            function upload() {
                                wx.uploadImage({
                                    localId: images.localId[lastindex],
                                    success: function (res) {
                                        $('#main_image').val(res.serverId);
                                        $('#uploadpic').val('可重新选择个人头像');
                                    },
                                    fail: function (res) {
                                        alert(JSON.stringify(res));
                                    }
                                });
                            }

                            if($.trim(res.localIds[lastindex])){
                                upload();
                            }
                        },

                        fail: function(res){
                            console.log(res);
                        }

                    });
                };
            }

            jsuploadpic();
            wx.error(function(res){
                alert(JSON.stringify(res));
            });


        });


    }



});




